<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<%@ page import="com.lagou.zuoye.dao.StudentDao" %>
<%@ page import="com.lagou.zuoye.dao.StudentDaoImp" %>
<%@ page import="com.lagou.zuoye.bean.Student" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/8/9
  Time: 13:17
  To change this template use File | Settings | File Templates.
--%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>Title</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<style>
</style>
<body>

<%--增加学员--%>
<form action="add" method="post" id="form1">

    <p>请输入要添加学员的姓名: <input type="text" name="name" /></p>
    <p>请输入要添加学员的性别: <input type="text" name="sex" /></p>
    <p>请输入要添加学员的出生日期: <input type="text" name="birthday" /></p>
    <p>请输入要添加学员的邮箱: <input type="text" name="email" /></p>
    <p>请输入要添加学员的备注: <input type="text" name="notes" /></p>

    <span style="color: red">
    <%= request.getAttribute("error")==null?"":request.getAttribute("error")%>
    </span>
    <br>
    <input type="submit" value="添加学员" />
</form>
<%--删除学员--%>
<form action="delete" method="post" id="form2">
    <p>请输入要删除学员的姓名：<input type="text" name = "name"/></p>
    <span style="color: red">
    <%= request.getAttribute("deleteError")==null?"":request.getAttribute("deleteError")%>
    </span>
    <input type="submit" value="删除学员"/>
</form>
<%--修改学员信息--%>
<form action="alter" method="post" id="form3">
    <p>请输入修改前学员的姓名: <input type="text" name="name" /></p>
    <p>请输入修改后学员的姓名: <input type="text" name="alterName" /></p>
    <p>请输入修改后学员的性别: <input type="text" name="sex" /></p>
    <p>请输入修改后学员的出生日期: <input type="text" name="birthday" /></p>
    <p>请输入修改后学员的邮箱: <input type="text" name="email" /></p>
    <p>请输入修改后学员的备注: <input type="text" name="notes" /></p>

    <span style="color: red">
    <%= request.getAttribute("alterError")==null?"":request.getAttribute("alterError")%>
    </span>
    <br>
    <input type="submit" value="修改学员" />
</form>
<%--根据姓名查询学员并打印学员信息--%>
<form action="select" method="post" id="form4">
    <p>请输入要查询学员的姓名: <input type="text" name="name" /></p>
    <span style="color: red">
    <%= request.getAttribute("selectError")==null?"":request.getAttribute("selectError")%>
    </span>
    <br>
    <input type="submit" value="查询学员" />
</form>
<% StudentDao studentDao = new StudentDaoImp();
    List<Student> students = studentDao.viewAllStudent();
    request.setAttribute("stus",students);
%>
<table border="1">
    <tr>
        <th>id</th>
        <th>姓名</th>
        <th>性别</th>
        <th>出生日期</th>
        <th>邮箱</th>
        <th>备注</th>
    </tr>
    <%--  使用foreach遍历students里的所有数据并打印  --%>
    <c:forEach items="${stus}" var="stu">
        <tr>
            <td>${stu.s_id}</td>
            <td>${stu.s_name}</td>
            <td>${stu.s_sex}</td>
            <td>${stu.s_birthday}</td>
            <td>${stu.s_email}</td>
            <td>${stu.s_notes}</td>
        </tr>
　　</c:forEach>　　
</table>
</body>
</html>
